package com.estronger.shopmanage.adapter.tasking;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.bean.DeliverTrip;
import com.estronger.shopmanage.utils.ConvertUtils;

import java.util.ArrayList;


public class DelivertripDetailAdpter extends BaseAdapter {

	private ArrayList<DeliverTrip.Datas.DatasDetail> mList;
	Context mContext;

	public DelivertripDetailAdpter(Context context, ArrayList<DeliverTrip.Datas.DatasDetail> lt) {
		mContext = context;
		mList = lt;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(mList != null)
			return mList.size();
		else
			return 0;
	}

	@Override
	public DeliverTrip.Datas.DatasDetail getItem(int position) {
		// TODO Auto-generated method stub
		if(mList == null || mList.size() <=0)
			return null;
		else
			return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		DeliverTrip.Datas.DatasDetail customer = mList.get(position);
		final ListItemView ltv;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.adpter_delivertripdetail, null);
			ltv = new ListItemView();
			ltv.targetname = (TextView) convertView
					.findViewById(R.id.targetname);
			ltv.yytime_tt = (TextView)convertView.findViewById(R.id.yytime_tt);
			ltv.deliveradr = (TextView) convertView.findViewById(R.id.deliveradr);

			convertView.setTag(ltv);
		} else {
			ltv = (ListItemView) convertView.getTag();
		}

		try {
			ltv.targetname.setText(ConvertUtils.formatNullF(customer.buildname) + ConvertUtils.formatNull(customer.cstname));
			String planDate = customer.pddate+"";
			if(planDate != null && !planDate.equals("") && planDate.contains(" ")){
				planDate = planDate.substring(planDate.indexOf(" ") + 1, planDate.length());
			}
			ltv.yytime_tt.setText(planDate);
			ltv.deliveradr.setText(ConvertUtils.formatNull(customer.address));

		} catch (Exception e) {
			e.printStackTrace();
		}

		return convertView;
	}

	class ListItemView {
		TextView targetname;
		TextView yytime_tt;
		TextView deliveradr;
	}
}
